// by Xeno

private ["_cam","_speed_str", "_fuel_str", "_dam_str", "_dir_str","_height_aim", "_gendirlist", "_welcome_message", "_vec", "_welcome_str", "_vec_msg1", "_struct_text", "_endtime", "_type_name", "_vec_string", "_vdir", "_gendir", "_dstr", "_count", "_control", "_type_weap", "_dirtmp"];
_speed_str = "Speed: %1 km/h";
_fuel_str =  "Fuel: %1";
_dam_str =   "Dam: %1";
_dir_str =   "Dir: %1 (%2)";
_height_aim =   "Aim: %1";
_gendirlist = ["N","N-NE","NE","E-NE","E","E-SE","SE","S-SE","S","S-SW","SW","W-SW","W","W-NW","NW","N-NW","N"];

disableSerialization;


while {true} do {
	waitUntil {sleep (0.2 + random 0.2);vehicle player != player};
	_vec = vehicle player;
	if (_vec isKindOf "LandVehicle" && !(_vec isKindOf "StaticWeapon")) then {
		while {vehicle player != player} do {
			if (player == driver _vec || player == gunner _vec || player == commander _vec) then {
				_type_name = [typeOf _vec,0] call XfGetDisplayName;
				_vec_string = format ["Vec: %1", _type_name];
				67327 cutRsc ["xvehicle_hud", "PLAIN"];
				_disp = uiNameSpace getVariable "DVEC_HUD";
				while {vehicle player != player && alive player && player == driver _vec} do {
					_control = _disp displayCtrl 64432;
					_control ctrlSetText _vec_string;
					_control = _disp displayCtrl 64433;
					_control ctrlSetText format [_speed_str, round (speed _vec)];
					_control = _disp displayCtrl 64434;
					_control ctrlSetText format [_fuel_str, round (fuel _vec * 100)];
					_control = _disp displayCtrl 64435;
					_control ctrlSetText format [_dam_str, round (damage _vec * 100)];
					_vdir = round (direction _vec);
					_gendir = _gendirlist select (round (_vdir/22.5));
					_control = _disp displayCtrl 64436;
					_control ctrlSetText format [_dir_str, _vdir, _gendir];
					sleep 0.331;
				};
				67327 cutRsc["DOM_RscNothing", "PLAIN",1];
			};
			sleep 0.532;
		};
	} else {
		if (_vec isKindOf "StaticWeapon") then {
			while {vehicle player != player} do {
				if (player == gunner _vec) then {
					// Only Cannons need to have a camera 
					If (_vec isKindOf "StaticCannon") then {
						sleep 2;
					} else {
						// All static other than mortar need the UI; mortars have the ARTY and LOG UI.
						if (!(_vec isKindOf "StaticMortar")) then {
							_type_name = [typeOf _vec,0] call XfGetDisplayName;
							_vec_string = format ["Vec: %1", _type_name];
							_type_weap = (getArray(configFile>>"CfgVehicles" >> (typeOf _vec) >> "Turrets" >> "MainTurret" >> "weapons")) select 0;
							67327 cutRsc ["xvehicle_hud", "PLAIN"];
							_disp =  uiNameSpace getVariable "DVEC_HUD";
							while {vehicle player != player && alive player && player == gunner _vec} do {
								_control = _disp displayCtrl 64432;
								_control ctrlSetText _vec_string;
								_control = _disp displayCtrl 64433;
								_control ctrlSetText format [_dam_str, round (damage _vec * 100)];
								_control = _disp displayCtrl 64434;
								_control ctrlSetText "";
								_control = _disp displayCtrl 64435;
								_dirtmp = round(((_vec weaponDirection _type_weap) select 0) atan2 ((_vec weaponDirection _type_weap) select 1));
								if (_dirtmp < 0) then {_dirtmp = _dirtmp + 360};
								_gendir = _gendirlist select (round (_dirtmp/22.5));
								_control ctrlSetText format [_dir_str, _dirtmp, _gendir];
								_control = _disp displayCtrl 64436;
								_control ctrlSetText "";
								sleep 0.331;
							};
							67327 cutRsc["DOM_RscNothing", "PLAIN",1];
						};
					};
				};
				sleep 0.532;
			};
		};
	};
	waitUntil {sleep (0.2 + random 0.2);vehicle player == player};	
};

if (true) exitWith {};


// OLD CODE inside StaticWeapon:
				// if (player == gunner _vec) then {
					// _type_name = [typeOf _vec,0] call XfGetDisplayName;
					// _vec_string = format ["Vec: %1", _type_name];
					// _type_weap = (getArray(configFile>>"CfgVehicles" >> (typeOf _vec) >> "Turrets" >> "MainTurret" >> "weapons")) select 0;
					// 67327 cutRsc ["xvehicle_hud", "PLAIN"];
					// _disp =  uiNameSpace getVariable "DVEC_HUD";
					// _cam = "camera" camCreate [];
					// while {vehicle player != player && alive player && player == gunner _vec} do {
						// _control = _disp displayCtrl 64432;
						// _control ctrlSetText _vec_string;
						// _control = _disp displayCtrl 64433;
						// _control ctrlSetText format [_dam_str, round (damage _vec * 100)];
						// _control = _disp displayCtrl 64434;
						// _control ctrlSetText "";
						// _control = _disp displayCtrl 64435;
						// _dirtmp = round(((_vec weaponDirection _type_weap) select 0) atan2 ((_vec weaponDirection _type_weap) select 1));
						// if (_dirtmp < 0) then {_dirtmp = _dirtmp + 360};
						// _gendir = _gendirlist select (round (_dirtmp/22.5));
						// _control ctrlSetText format [_dir_str, _dirtmp, _gendir];
						// _control = _disp displayCtrl 64436;
						// // We only want the aiming height for cannons and mortars
						// If ((_vec isKindOf "StaticCannon") OR (_vec isKindOf "StaticMortar")) then {
							// _control ctrlSetText format [_height_aim, asin((_vec weaponDirection _type_weap) select 2)];
						// } else {
							// _control ctrlSetText "";
						// };
						// sleep 0.331;
					// };
					// 67327 cutRsc["DOM_RscNothing", "PLAIN",1];
				// };
				// sleep 0.532;
